package com.niiwoo.civet.mobile.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.niiwoo.civet.mobile.vo.request.UserBusinessTypeUpdateRequestDTO;
import com.niiwoo.civet.mobile.vo.response.UserBusinessTypeTwoConfirmResponseDTO;
import com.niiwoo.civet.mobile.vo.response.user.UserIdentityTagResponseVO;
import com.niiwoo.civet.trade.service.project.NovicePorjectDubboService;
import com.niiwoo.tripod.web.util.PrincipalContext;
import com.niiwoo.tripod.web.vo.Empty;
import com.niiwoo.tripod.web.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * Created by wuke on 2017/10/12
 */
@RestController
@RequestMapping("/userBusinessType")
@Api(tags = "用户身份", description = "/userBusinessType")
public class UserBusinessTypeController {

    @Reference(version = "1.0.0")
    private NovicePorjectDubboService novicePorjectDubboService;

    @PostMapping("/userBusinessTypeUpdate")
    @ApiOperation("用户身份变更")
    public Empty userBusinessTypeUpdate(@RequestBody @Valid UserBusinessTypeUpdateRequestDTO dto) {

        return Empty.getInstance();
    }

    @PostMapping("/userBusinessTypeTwoConfirm")
    @ApiOperation("用户身份二次确认查询")
    public Result<UserBusinessTypeTwoConfirmResponseDTO> userBusinessTypeTwoConfirm() {
        UserBusinessTypeTwoConfirmResponseDTO resDTO = new UserBusinessTypeTwoConfirmResponseDTO();
        return Result.with(resDTO);
    }


    @PostMapping("/userIdentityTag/V560")
    @ApiOperation("用户身份查询")
    public Result<UserIdentityTagResponseVO> userIdentityTag() {
        String userId = PrincipalContext.getUserId();
        UserIdentityTagResponseVO responseVO = new UserIdentityTagResponseVO();
        if (StringUtils.isNotBlank(userId)) {
            Byte userIdentityTag = novicePorjectDubboService.queryUserIdentity(userId);
            if (userIdentityTag == 0/* || userIdentityTag == 2*/) {
                responseVO.setUserIdentityTag((byte) 0);
            } else {
                responseVO.setUserIdentityTag((byte) 1);
            }
        } else {
            responseVO.setUserIdentityTag((byte) 0);
        }
        return Result.with(responseVO);
    }

}
